<template>
  <el-container class="center-container">
    <el-card class="info-container">
      <h2>假期详情</h2>
      <el-table :data="leaveRecords" v-if="leaveRecords.length">
        <el-table-column prop="leaveType" label="假期类型"></el-table-column>
        <el-table-column prop="startDate" label="开始日期"></el-table-column>
        <el-table-column prop="endDate" label="结束日期"></el-table-column>
        <el-table-column prop="reason" label="原因"></el-table-column>
        <el-table-column prop="status" label="状态"></el-table-column>
      </el-table>
      <el-empty v-else description="无假期记录"></el-empty>
    </el-card>
  </el-container>
</template>

<script>
export default {
  props: {
    employeeId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      leaveRecords: []
    };
  },
  mounted() {
    this.fetchLeaveRecords();
  },
  methods: {
    async fetchLeaveRecords() {
      try {
        const response = await this.$axios.get(`/api/leave/employee/${this.employeeId}`);
        console.log('API Response:', response.data); // 调试输出
        this.leaveRecords = response.data;
      } catch (error) {
        console.error('Error fetching leave records:', error);
      }
    }
  }
};
</script>

<style scoped>
.center-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}
.info-container {
  border: 1px solid #dcdfe6;
  padding: 20px;
  border-radius: 5px;
  background-color: #f9f9f9;
  max-width: 900px;
  width: 100%;
}
.el-card {
  padding: 20px;
}
</style>
